<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Sign;
use App\Models\HospitalUserFamily;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SignController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Sign(['family','team','hospital']), function (Grid $grid) {
            $grid->column('user_id');
            $grid->column('family.name','签约人姓名');
            $grid->column('team.name','签约团队');
            $grid->column('hospital.name','签约社区');
            $grid->column('status')->using(HospitalUserFamily::$statusTxt);
            $grid->column('endtime');
            $grid->column('starttime');
            $grid->column('type')->using(HospitalUserFamily::$typeTxt);
            $grid->column('is_sign')->using(HospitalUserFamily::$isSignTxt);
            $grid->column('contract_extension_at');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('family_id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Sign(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('family_id');
            $show->field('hospital_team_id');
            $show->field('hospital_id');
            $show->field('status');
            $show->field('endtime');
            $show->field('starttime');
            $show->field('type');
            $show->field('is_sign');
            $show->field('contract_extension_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Sign(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('family_id');
            $form->text('hospital_team_id');
            $form->text('hospital_id');
            $form->text('status');
            $form->text('endtime');
            $form->text('starttime');
            $form->text('type');
            $form->text('is_sign');
            $form->text('contract_extension_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
